package com.laan.bmagame;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class LaanIntro extends Activity {
	
	Thread thrLoading;
	boolean stopped;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.app_loading);
        
        //variables globals
  		GV.Screen.metrics = new DisplayMetrics();
  		getWindowManager().getDefaultDisplay().getMetrics(GV.Screen.metrics);
        
        ImageView rodaLoadGran = (ImageView)findViewById(R.id.RodaLoadGran);
		rodaLoadGran.startAnimation(AnimationUtils.loadAnimation(this, R.anim.rotate_load_slow));
		
		ImageView rodaLoad = (ImageView)findViewById(R.id.RodaLoad);
		rodaLoad.startAnimation(AnimationUtils.loadAnimation(this, R.anim.rotate_load));
		
		stopped = false;
		thrLoading = new Thread(){
			public void run(){
				try{
					sleep(2000);
					if(!stopped) {
						Intent i = new Intent("com.laan.bmagame.LAANMAIN");
						startActivity(i);
					}
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				finally{
					finish();
				}
			}
		};
		thrLoading.start();
	}

	@Override
	protected void onStop() {
		super.onStop();
		stopped = true;
		//fer join del thread en el cas de que no estigues dormint
	}
	
	@Override
	public void onBackPressed() {
		finish();
		//activity transition animation
		super.onBackPressed();
	}
}